var oRoot={'debug':false};

oRoot.inspect=function(obj){
	if(typeof obj != 'object'){
		return obj;
	}
	var a=[];
	try{
		for(property in obj){
			var content=obj[property];
			a.push(property+':'+content);
		}
	}catch(e){
		alert(e.message);
	}
	return a;
};
var inspect=oRoot.inspect;

oRoot.look=function(obj){
	var aView=oRoot.inspect(obj);
	alert(aView.join('\n'));
};
var look=oRoot.look;

oRoot.util={
	addTextContent:function(oTarget,text){
		oTarget.appendChild(document.createTextNode(text));
	},
	getFirstObjByName:function(sName){
		var a=$$(sName);
		if(a.length>0){
			return a[0];
		}else{
			return null;
		}
	},
	getPropertyArray:function(o){
		var a={};
		for(p in o){
			a[p]=p;
		}
		return a;
	},
	changeDisplay:function(oTr){
		var oTable=oTr.nextSibling;
		if(oTable){
			oTable.style.display=oTable.style.display=='none'?'':'none';
		}
	},
	showHand:function(obj){
		if(!obj){
			obj=event.srcElement;
		}
		obj.style.cursor="hand";
	},
	null2empty:function(s){
		return s!='null'?s:'';
	},
	isEmpty:function(o){
		if(!o){
			return o;
		}
		for(p in o){
			return false;
		}
		return true;
	},
	setHiddensByObj:function(o,container){
		if(!container){
			container=document.body;
		}
		var inputT=templateNode.hiddenT;
	 	for(p in o){
	 		var strName = p;
		 	var strValue = o[p];
		
			if ($(strName)){
		 	 	$(strName).value=strValue;
		 	}else{
			 	var input = inputT.cloneNode();
			 	input.id = strName;
				input.name = strName;
				input.value = strValue;
				container[add](input);
			}
	 	}
	},
	getSelectedText:function(oSelect){
		if(typeof oSelect=='string'){
			oSelect=$f(oSelect);
		}
		var index=oSelect.selectedIndex;
		return oSelect.options[index].text;
	},
	buildLetterSelect:function(){
		var oSelect=document.createElement('select');
		oSelect.id='letters';
		var add='appendChild';
		var sOption='option';
		var sValue='value';
		
		for(var i=65;i<=90;i=i+1){
			var letter=String.fromCharCode(i);
			var oOption=document.createElement(sOption);
			oOption[sValue]=letter;
			oOption[add]($tn(letter));
			oSelect[add](oOption);
		}
		
		addDefult(oSelect);
		return oSelect;
	},
	addDefaultOption:function(oSelect){
		var o=$c('option');
	    o[set]('value','');
	    o[add]($tn(defaultOption));
	    var firstOption=oSelect[fir];
	    firstOption[par][ins](o,firstOption);
	    oSelect.value='';
	},
	reload:function(){
		document.location.reload();
	},
	deleteRows:function(t,a){
		if(a.has){
			for(var i=0;i<a.length;i=i+1){
				var rownum=a[i];
				if(t.rows.length>rownum){
					t.deleteRow(rownum);
				}
			}
		}else if(typeof a==='number'){
			t.deleteRow(a);
		}
	},
	likeLink:function(){
		if(!event){
			return;
		}
		var Me=event.srcElement;
		Me.style.cursor="hand";
		Me.style.textDecoration="underline";
	},
	getCDATAContent:function(oRow,sName){
		var node=oRow[gett](sName)[0];
		if(node.hasChildNodes()&&node.firstChild.nodeType===4){
			return node.firstChild.nodeValue;
		}
		return '';
	},
	getUnicodeLength:function(s){
		return s.replace(/[^\x00-\xff]/g,"xx").length;
	},
	getTdContent:function(oTd){
		if(oTd&&oTd.hasChildNodes()){
			if(oTd.firstChild.nodeType==Node.TEXT_NODE){
				return oTd.firstChild.data;
			}else if(oTd.firstChild.nodeType==Node.ELEMENT_NODE){
				return getTdContent(oTd.firstChild);
			}else{
				return '';
			}
		}
	}
};
var util=oRoot.util;
var addTextContent=oRoot.util.addTextContent;
var null2empty=oRoot.util.null2empty;
var showHand=oRoot.util.showHand;
var $dt=oRoot.util.changeDisplay;
var $f=oRoot.util.getFirstObjByName;
var isEmpty=util.isEmpty;
var $sh=util.setHiddensByObj;
var $st=util.getSelectedText;
var getLetterList=util.buildLetterSelect;
var reload=util.reload;
var addDefult=util.addDefaultOption;
var deleteRows=util.deleteRows;
var likeLink=util.likeLink;
var getCDATAContent=util.getCDATAContent;
var getUnicodeLength=util.getUnicodeLength;
var getTdContent=util.getTdContent;

oRoot.util.getSelectedRadio=function(radioName){
	var aRadio=$$(radioName);
	for(var i=0;i<aRadio.length;i=i+1){
		var oRadio=aRadio[i];
		if(oRadio.checked){
			return oRadio;
		}
	}
};

oRoot.util.setValuesByName=function(sName,sValue){
  	var aControl=$$(sName);
  	var iLength=aControl.length;
  	for (var i=0;i<iLength;i=i+1){
  		var obj=aControl[i];
  		if(obj.parentNode&&obj.parentNode.id=='stay'){
  			continue;
  		}
    	obj.value=sValue;
    }
};
var setValuesByName=oRoot.util.setValuesByName;

oRoot.util.checkNotNull=function(){
	var aInput=document.getElementsByTagName('input');
	var iLength=aInput.length;
	for(var i=0;i<iLength;i=i+1){
		var oInput=aInput[i];
		if(oInput.value.length===0){
			promptNotNull(oInput.previousSibling.data);
			oInput.focus();
			return false;
		}
	}
	return true;
};

oRoot.util.display=function(name,value){
	var tag,td;
	if(typeof name == 'string'){
		name=$$(name);
	}
	for(var i=0;i<name.length;i=i+1){
		tag=name[i];
		if(tag.nodeName=='TD'){
			td=document.createElement('TD');
			td.className=tag.className;
			tag.parentNode[add](td);
		}
		tag.style.display=value;
	}
};
var dis=oRoot.util.display;

oRoot.util.removeNodes=function(aNodes){
	var i,a=[];
	var iLength=aNodes.length;
	for(i=0;i<iLength;i=i+1){
		var node=aNodes[i];
		a.push(node);
	}
	iLength=a.length;
	for(i=0;i<iLength;i=i+1){
		a[i].removeNode();
	}
};

oRoot.util.insertHiddensToForm=function(aNames,oQcClone){
	var oForm=document.forms[0];
	var iLength=aNames.length;
	for(var i=0;i<iLength;i=i+1){
		oQcClone=oQcClone.cloneNode(true);
		oQcClone.value=aNames[i];
		oForm.insertAdjacentElement('afterBegin',oQcClone);
	}
};

oRoot.util.getElement=function(arg){
	if(typeof arg == 'string'){
		return document.getElementById(arg);
	}
	if(typeof arg == 'object'){
		return arg;
	}
};

oRoot.util.getElements=function(arg){
	if(typeof arg == 'string'){
		return document.getElementsByName(arg);
	}
	if(typeof arg == 'object'){
		return arg;
	}
};

oRoot.util.getTags=function(tagName){
	if(typeof tagName == 'string'){
		return document.getElementsByTagName(tagName);
	}
	if(typeof tagName == 'object'){
		return tagName;
	}
};

oRoot.Pager=function(target,pagelinks,pageSize,buildRow){
	var oTarget=$(target);
	if(!oTarget){
		//alert('请指定目标容器！');
		oTarget=$c('div');
		oTarget.id=target;
		document.body.appendChild(oTarget);
	}
	if(oTarget.getElementsByTagName('table').length!=0){
		//oTarget.innerHTML='';
	}
	this.target=target;
	this.pagelinks=pagelinks;
	if(pageSize){
		this.pageSize=pageSize;
	}else{
		this.pageSize=10;
	}
	this.buildRow=buildRow;
	this.rowCount=0;
	this.pageLoadIndex=0;
	this.oData=new cXMLLoader().getXmlDoc();
	this.oData.loadXML('<root/>');
	this.currentPage=0;
	this.pageCount=0;
	this.originalQueryDocument=null;
	
	this.PAGE_NAME='page_';
	this.PAGE_LINK='pageLink_';
	
	this.ACTIVE_COLOR='blue';
	this.UNACTIVE_COLOR='black';
};

var Pager=oRoot.Pager;

Pager.prototype={
	toString:function(){
		var a=[];
		a.push('currentPage:'+this.currentPage);
		a.push('\ntarget:'+this.target);
		a.push('\npagelinks:'+this.pagelinks);
		a.push('\npageSize:'+this.pageSize);
		a.push('\noData:'+this.oData);
		return a.join('');
	},
	toNextPage:function(){
		this.gotoPage(this.currentPage+1);
	},
	toLastPage:function(){
		this.gotoPage(this.currentPage-1);
	},
	createPageList:function(){
		var sOut='';
		sOut+='<ul>';
		for(var i=0;i<this.pageCount;i=i+1){
			sOut+='<li>';
			sOut+='<a id=pageLink_'+i+' href=# onclick="return false;" value='+i+'>';
			sOut+='['+(i+1)+']';
			sOut+='</a>';
			sOut+='</li>';
		}
		sOut+='</ul>';
		$(this.pagelinks)[inn]=sOut;
		for(i=0;i<this.pageCount;i=i+1){
			insertEvent($(this.PAGE_LINK+i),'onclick',this.gotoPage.bind(this));
		}
	},
	gotoPage:function(){
		var pageIndex=event.srcElement.value;
		var pageName=this.PAGE_NAME;
		var thatPage=$(pageName+pageIndex);
		if(thatPage){
			$d(pageName+this.currentPage,'none');
			$d(thatPage,'');
		}else{
			var oTable=this.getPage(pageIndex);
			if(!oTable){
				return false;
			}
			$(this.target)[add](oTable);
			$d(pageName+this.currentPage,'none');
			$d(oTable,'');
		}
		this.changeLinkColor(pageIndex);
		this.currentPage=pageIndex;
		return true;
	},
	changeLinkColor:function(pageIndex){
		this.changeToUnActive();
		this.changeToActive(pageIndex);
	},
	changeToActive:function(pageIndex){
		$(this.PAGE_LINK+pageIndex).style.color=this.ACTIVE_COLOR;
	},
	changeToUnActive:function(){
		$(this.PAGE_LINK+this.currentPage).style.color=this.UNACTIVE_COLOR;
	},
	getPage:function(pageIndex){
		var Me=this;
		var oTable=$c('table');
		oTable.border="1";
		oTable.cellpadding="2";
		oTable.cellspacing="0";
		oTable.bordercolorlight="#B6D76D";
		oTable.bordercolordark="#FFFFFF";
		oTable.id=Me.PAGE_NAME+pageIndex;
		oTable.width='100%';
		oTable.className='unnamed6';
		var oTbody=$c('tbody');
		oTable[add](oTbody);
		var pageData=this.oData.documentElement.getElementsByTagName(Me.PAGE_NAME+pageIndex)[0];
		var rows=pageData.childNodes;
		for(var i=0;i<rows.length;i=i+1){
			var oRow=Me.buildRow(rows,i);
			oTbody[add](oRow);
		}
		return oTable;
	},
	getData:function(http){
		var Me=this;
		var root=http.responseXML.documentElement;
		Me.rowCount=root.getAttribute('rowCount');
		if(Me.rowCount<=0){
			if(WaitingBar){
	    		WaitingBar.hideMe();
	    	}
	    	alert("没有符合条件的数据！");
	    	return false;
	    }
	    if(Me.oData){
			Me.oData.documentElement[add](root);
	    }
		Me.pageCount=Math.ceil(Me.rowCount/Me.pageSize);
	    return Me.getFirstPageData();
	},
	getNextData:function(http){
		var Me=this;
		var root=http.responseXML.documentElement;
		if(Me.oData){
			Me.oData.documentElement[add](root);
	    }
	    Me.pageLoadIndex=Me.pageLoadIndex+1;
	},
	getNextPageData:function(){
		var Me=this;
		for(var i=1;i<Me.pageCount;i=i+1){
			var root=this.originalQueryDocument.documentElement;
			root[set]('pageIndex',i);
			doRequest("servlet/startup",root.xml,Me.getNextData.bind(Me));
		}
		return true;
	},
	getFirstPageData:function(){
		var Me=this;
	    var firstPage=Me.getPage(0);
	    var pageCode;
	    if(firstPage){
	    	pageCode=firstPage;
	    }else{
	    	pageCode=$c('p');
	    	var oTn=$tn('没有符合条件的数据！');
	    	pageCode[add](oTn);
	    }
	    var oTarget=$(Me.target);
	    oTarget[inn]=pageCode[out];
	    Me.createPageList();
	    Me.changeLinkColor(0);
	    if(WaitingBar){
    		WaitingBar.hideMe();
    	}
    	Me.pageLoadIndex=1;
    	Me.getNextPageData();
	    return true;
	}
};

oRoot.cXMLLoader=function(xmlPath){
	var xmlDoc;
	if(xmlPath){
		this.setXmlPath(xmlPath);
	}
	this.getDoc();
};
var cXMLLoader=oRoot.cXMLLoader;

cXMLLoader.prototype={
	loadXML:function(){
		var xmlDoc=this.getXmlDoc();
		var xmlPath=this.getXmlPath();
		if(!xmlDoc){
			if(window.ActiveXObject){
				xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
				xmlDoc.async = false;
			}else if (document.implementation&&document.implementation.createDocument){
				xmlDoc = document.implementation.createDocument('', '', null);
			}else{
				return false;
			}
		}
		if(xmlPath){
			xmlDoc.load(xmlPath);
		}
		this.setXmlDoc(xmlDoc);
		return true;
	},
	
	checkXMLDocObj:function(){
		if(!this.loadXML()){
			window.alert('!');
			return false;
		}
		return true;
	},
	
	getDoc:function(){
		if(!this.getXmlPath()){
			this.setXmlPath(this.xmlPath);
		}
		return this.checkXMLDocObj();
	},
	
	getXmlDoc:function(){
		return this.xmlDoc;
	},
	
	setXmlDoc:function(xmlDoc){
		this.xmlDoc=xmlDoc;
	},
	
	getXmlPath:function(){
		return this.xmlPath;
	},
	
	setXmlPath:function(xmlPath){
		this.xmlPath=xmlPath;
	}
};

oRoot.oFilters={
	//对象方式的下拉框过滤
	CObjDropDownFilter:function(obj){
		var cacheDropDown=obj.cloneNode(true);
		this.getCacheDropDown=function(){
			return cacheDropDown;
		};
		obj.replaceNode(obj.cloneNode());//清空下拉列表
		var o={};
		var oResultSelect=false;
		
		var toO=function(){
			var aOptions=cacheDropDown.childNodes;
			for(var i=0;i<aOptions.length;i=i+1){
				var oOption=aOptions[i];
				o[oOption.value]=oOption.innerText;
			}
		};
		toO();
		
		this.search=function(str){
			var oSelect=cacheDropDown.cloneNode();
			for(s in o) {
				if(typeof(s)=='string'&&s!='undefined'&&o[s].search(str)!=-1){
					var oOption=$c('option');
					oOption.value=s;
					oOption.appendChild($tn(o[s]));
					oSelect.appendChild(oOption);
				}
			}
			oResultSelect=oSelect;
		};
		
		this.render=function(){
			if(oResultSelect){
				var sId=obj.id?obj.id:obj.name;
				$(sId).replaceNode(oResultSelect);
			}
		};
	}
};

var oFilters=oRoot.oFilters;
var anotherFilters={
	//对象方式的下拉框过滤
	CObjDropDownFilter:function(obj){
		var caheDropDown=obj.cloneNode(true);
		this.getCacheDropDown=function(){
			return cacheDropDown;
		};
		obj.replaceNode(obj.cloneNode());//清空下拉列表
		var o={};
		var oResultSelect=false;
		
		var toO=function(){
			var aOptions=cacheDropDown.childNodes;
			for(var i=0;i<aOptions.length;i=i+1){
				var oOption=aOptions[i];
				o[oOption.value]=oOption.innerText;
			}
		};
		toO();
		
		this.search=function(str){
			var oSlect=cacheDropDown.cloneNode();
			for(s in o) {
				if(typeof(s)=='string'&&s!='undefined'&&o[s].search(str)!=-1){
					var oOption=$c('option');
					oOption.value=s;
					oOption.appendChild($tn(o[s]));
					oSelect.appendChild(oOption);
				}
			}
			oResultSelect=oSelect;
			this.render();
		};
		
		this.render=function(){
			if(oResultSelect){
				var sId=obj.id?obj.id:obj.name;
				$(sId).replaceNode(oResultSelect);
			}
		};
	}
};

/*为数组增加has方法，测试该数组是否包含参数，引用此文件的数字将都有此功能*/
Array.prototype.has=function(obj){
	for(var i=0;i<this.length;i=i+1){
		if(this[i]==obj){
			return true;
		}
	}
	return false;
};

var Node={
    ELEMENT_NODE:'1',
    ATTRIBUTE_NODE:'2',
    TEXT_NODE:'3',
    CDATA_SECTION_NODE:'4',
    ENTITY_REFERENCE_NODE:'5',
    ENTITY_NODE:'6',
    PROCESSING_INSTRUCTION_NODE:'7',
    COMMENT_NODE:'8',
    DOCUMENT_NODE:'9',
    DOCUMENT_TYPE_NODE:'10',
    DOCUMENT_FRAGMENT_NODE:'11',
    NOTATION_NODE:'12'
};

var emptyFunc = function() {};

var addEvent=function(obj,eventName,func){
	combineEvent(obj,eventName,func,addFunc);
};

var insertEvent=function(obj,eventName,func){
	combineEvent(obj,eventName,func,insertFunc);
};

var combineEvent=function(obj,eventName,newfunc,position){
	if(!obj){
		return false;
	}
	var oldfunc=obj[eventName];
	if(typeof obj[eventName] != fuc){
		obj[eventName]=newfunc;
	}else{
		obj[eventName]=function(){
			return position(oldfunc,newfunc);
		};
	}
};

var insertFunc=function(oldfunc,newfunc){
	newfunc();
	return oldfunc();
};

var addFunc=function(oldfunc,newfunc){
	oldfunc();
	return newfunc();
};

var addOnloadEvent=function(func){
	addEvent(window,onl,func);
};

var addOnclick=function(obj,func){
	addEvent(obj,clk,func);
};

var insertOnclick=function(obj,func){
	insertEvent(obj,clk,func);
};

var returnFalse=function(){
	return false;
};

var insertAfter=function(newElement,targetElement){
	var parentElement=targetElement.parentNode;
	if(targetElement===parentElement.lastChild){
		parentElement[add](newElement);
	}else{
		parentElement[ins](newElement,targetElement[next]);
	}
};

/**重复
function insertAfter(oNewNode,oChildNode){
	var nextNode=oChildNode.nextSibling;
	if(nextNode){
		oChildNode.parentNode.insertBefore(oNewNode,nextNode);
	}else{
		oChildNode.parentNode.appendChild(oNewNode);
	}
}
**/

//内置函数
var out='outerHTML';
var inn='innerHTML';
var add='appendChild';
var ins='insertBefore';
var set='setAttribute';
var get='getAttribute';
var gete='getElementById';
var gett='getElementsByTagName';
var atce='attachEvent';
var crt='createElement';
//event
var clk='onmouseup';
//内置属性和值
var onl='onload';
var href='href';
var fuc='function';
var len='length';
var val='value';
var ndt='nodeType';
var ndv='nodeValue';
var ndn='nodeName';
var id='id';
var na='name';
var esrc='srcElement';
var par='parentNode';
var fir='firstChild';
var las='lastChild';
var next='nextSibling';
//自定义函数
var ina=insertAfter;
window['addOnl']=addOnloadEvent;
//自定义属性和值
var defaultOption='默认全部';
var boMethod='BO_METHOD';
var unspecified='未指定';

/**创建模板节点 start*/
var templateNode=new function(){
	this.trT=$c('tr');
	this.tdT=$c('td');
	this.inputT=$c('input');
	this.hiddenT=this.inputT.cloneNode();
	this.hiddenT.type='hidden';
	this.cbT=this.inputT.cloneNode();
	this.cbT.type='checkbox';
	this.textT=this.inputT.cloneNode();
	this.textT.type='text';
	this.btnT=this.inputT.cloneNode();
	this.btnT.type='button';
	this.divT=$c('div');
	this.tnT=$tn('');
	this.buttonT=$c('button');
	this.buttonT.appendChild(this.tnT);
	this.formT=$c('form');
	this.formT.method='post';
	this.tableT=$c('table');
	var getHiddenClone=function(){
		return this.inputT.cloneNode(true);
	};
};
/**创建模板节点 end*/

/*表格工厂，性能低，需要改造成复制模板节点的方式*/
var tableFactory=new function(){
	this.getTable=function(){
		return templateNode.tableT.cloneNode();
	};
	this.getTd=function(){
		return templateNode.tdT.cloneNode();
	};
	this.getTr=function(){
		return templateNode.trT.cloneNode();
	};
};

oRoot.Collector=function(complexArray){
	this.complexArray=complexArray;
	this.xmlDocument=new XMLDocument();
	this.xmlDocument.addRoot('order');
};
var Collector=oRoot.Collector;
Collector.prototype={
	getElement:function(arrayIndex){
		var regionName=this.complexArray[arrayIndex];
		var complex=document.getElementsByName(regionName);
		var doc=this.xmlDocument;
		var listTag=doc.getNewTag('list');
		listTag.setAttribute('flag','1');
		listTag.setAttribute('name',complex.length>0?complex[0].getAttribute('name'):'');
		for(var i=0;i<complex.length;i=i+1){
			var item=complex[i];
			var itemValue='';
			if(item.tagName=='TEXTAREA'){
				itemValue=getEditorHTMLContents(item.id);
			}else{
				itemValue=item.value;
			}
			//必填元素
			if(itemValue.length==0&&item.parentNode.getElementsByTagName('span').length>1){
				alert('请填写：'+item.parentNode.firstChild.firstChild.data.replace(/：/g,''));
				item.focus();
				return false;
			}
			var itemTag=doc.getNewTag('item');
			itemTag.setAttribute('name',item.id);
			var cdata;
			if(item.tagName=='INPUT'&&item.type=='checkbox'){
				cdata=item.checked?'1':'0';
			}else{
				cdata=itemValue;
			}
			var cdataSection=doc.xmlDocument.createCDATASection(cdata);
			itemTag.appendChild(cdataSection);
			listTag.appendChild(itemTag);
		}
		return listTag;
	},
	buildDocument:function(){
		var root=this.xmlDocument.getRoot();
		for(var i=0;i<this.complexArray.length;i=i+1){
			var newElement=this.getElement(i);
			if(!newElement){
				return false;
			}
			root.appendChild(newElement);
		}
		return true;
	}
};

/**
 * 前台对分页支持的类
 * 根据后台返回的XML数据展现多页结构
 */
var AjaxPager=function(parameterObject){
	this.rootContainer=parameterObject['rootContainer'];
	this.container=parameterObject['container'];
	this.currentDisplay=parameterObject['currentDisplay'];
	this.receivedDocument=parameterObject['responseXML'];
	this.template=parameterObject['template'];//row,detail,title
	this.itemMap=parameterObject['itemMap'];
	this.addDetail=parameterObject['template']['detail']&&parameterObject['itemMap'];
	var ifMutiPage=parameterObject['ifMutiPage'];
	this.ifMutiPage=typeof ifMutiPage == 'undefined'?true:ifMutiPage;
	
	this.rowsPerPage=5;
	this.pageIdPre=this.container.id+'_page_';
	this.jsonObject=[];
	this.rowCount=0;
	this.pageCount=0;
	
	this.currentPage=null;
	this.contentDiv=null;
	this.detailDiv=null;
	this.pagerDiv=null;
	this.pageSizes=null;
	this.returnButtonDiv=null;
	this.returnFunction=null;
	this.currentRow=0;
	
	this.init();
};
oRoot.AjaxPager=AjaxPager;
AjaxPager.prototype={
	init:function(){
		this.transformXML();
	},
	render:function(){
		this.container.innerHTML='';
		this.createContentDiv();
		this.createPageLinkDiv();
		this.updateCounts();
		this.createPageLinks();
		this.createPageSizeSelect();
		this.createFirstPage();
		//this.addReturnButton();
		this.container.appendChild(this.contentDiv);
		//如果不分页则不渲染页码和页大小选择器
		//这两个对象应该合为一个
		if(this.ifMutiPage){
			this.container.appendChild(this.pagerDiv);
			this.container.appendChild(this.pageSizes);
			//this.container.appendChild(this.returnButtonDiv);
		}
		//putFront(this.container);
	},
	transformXML:function(){
		this.jsonObject=transformXML(this.receivedDocument);
		//look(this.jsonObject[0]);
	},
	updateCounts:function(){
		this.rowCount=this.jsonObject.length;
		if(this.rowsPerPage==0){
			this.rowsPerPage=Number.MAX_VALUE;
		}
		this.pageCount=Math.ceil(this.rowCount/this.rowsPerPage);
	},
	createContentDiv:function(){
		this.contentDiv=document.createElement('div');
		this.contentDiv.setAttribute('currentPage','0');
	},
	createDetailDiv:function(){
		var detailDivId='AjaxPager____detailDiv';
		if($(detailDivId)){
			this.detailDiv=$(detailDivId);
			this.detailDiv.innerHTML='';
		}else{
			this.detailDiv=document.createElement('div');
			this.detailDiv.id=detailDivId;
		}
	},
	createPageLinkDiv:function(){
		this.pagerDiv=document.createElement('div');
		this.pagerDiv.className='scott';
		var pager_content=document.createElement('div');
		this.pagerDiv.appendChild(pager_content);
	},
	createPages:function(){
		for(var i=0;i<this.pageCount;i=i+1){
			this.createPage(i);
		}
	},
	createPage:function(pageIndex){
		var pageFirstRowIndex=this.rowsPerPage*pageIndex;
		var pageLastRowIndex=0;
		if((pageFirstRowIndex+this.rowsPerPage)<this.rowCount){
			pageLastRowIndex=pageFirstRowIndex+this.rowsPerPage;
		}else{
			pageLastRowIndex=this.rowCount;
		}
		this.currentPage=document.createElement('div');
		this.currentPage.id=this.pageIdPre+pageIndex;
		this.currentPage.className='box';
		this.contentDiv.setAttribute('currentPage',pageIndex);
		if(this.template['title']){
			var oTitle=this.template['title']();
			this.currentPage.appendChild(oTitle);
		}
		for(var i=pageFirstRowIndex;i<pageLastRowIndex;i=i+1){
			var list=this.jsonObject[i];
			var row=this.template['row'](list);
			if(this.addDetail){
				/***由于一些管理功而取消***/
				//row.onclick=this.showDetail.bind(this,i);
				this.attachLinkEvent(row);
			}
			this.currentPage.appendChild(row);
		}
		this.contentDiv.innerHTML='';
		this.contentDiv.appendChild(this.currentPage);
		return false;
	},
	/***临时将转向详细信息的事件加到list中所有a标签上，以后需要修改***/
	attachLinkEvent:function(row){
		var targets=row.getElementsByTagName('a');
		for(var i=0;i<targets.length;i=i+1){
			var target=targets[i];
			target.onclick=this.showDetail.bind(this,i);
			if(target.style){
				target.style.cursor='hand';
			}
		}
	},
	createFirstPage:function(){
		this.createPage(0);
	},
	createPageLinks:function(){
		if(!this.ifMutiPage){
			return false;
		}
		this.pagerDiv.innerHTML='';
		for(var i=0;i<this.pageCount;i=i+1){
			var pageLink=document.createElement('a');
			pageLink.setAttribute('href','');
			//pageLink.setAttribute('className','arr');
			pageLink.appendChild(document.createTextNode(i+1));
			pageLink.onclick=this.createPage.bind(this,i);
			this.pagerDiv.appendChild(document.createTextNode(' '));
			this.pagerDiv.appendChild(pageLink);
			this.pagerDiv.appendChild(document.createTextNode(' '));
		}
	},
	createPageSizeSelect:function(){
		if(!this.ifMutiPage){
			return false;
		}
		var Me=this;
		this.pageSizes=document.createElement('span');
		this.pageSizes.className='bottomSelect';
		this.pageSizes.appendChild(document.createTextNode('每页显示的条数：'));
		var oSelect=document.createElement('select');
		oSelect.id=this.container.id+'_selectPageSize';
		this.pageSizes.appendChild(oSelect);
		oSelect.onchange=function(){
			var size=window.event.srcElement.value;
			Me.rowsPerPage=size;
			Me.render();
		};
		for(var i=1;i<=10;i=i+1){
			var size=document.createElement('option');
			var sizeValue=5*i;
			if(sizeValue==this.rowsPerPage){
				size.selected=true;
			}
			size.value=sizeValue;
			size.appendChild(document.createTextNode(sizeValue));
			oSelect.appendChild(size);
		}
		var size=document.createElement('option');
		size.value='0';
		size.appendChild(document.createTextNode('全部'));
		oSelect.appendChild(size);
	},
	showDetail:function(rowIndex){
		this.currentRow=rowIndex;
		var currentRow=window.event.srcElement;
		this.createDetailDiv();
		this.rootContainer.appendChild(this.detailDiv);
		hide(this.currentDisplay);
		show(this.detailDiv);
		this.template['detail'](this);
		//在应用模板之后需要增加对返回方式的支持，目前打算使用滚动跟随的方式支持返回
		return false;
	},
	showDetailInPopup:function(rowIndex){
		var currentRow=window.event.srcElement;
		var detailInfo=produceDetailInfo(this.jsonObject[rowIndex],this.itemMap);
		var oPopup=window.createPopup();
		var oPopBody = oPopup.document.body;
		oPopBody.style.backgroundColor = "lightyellow";
		oPopBody.style.border = "solid black 1px";
		oPopBody.innerHTML = detailInfo.outerHTML;
		oPopup.show(300, 300, 300, 300, document.body);
	},
	addReturnButton:function(){
		//if(true)return;
		if(!this.ifMutiPage){
			return false;
		}
		this.returnButtonDiv=document.createElement('div');
		this.returnButtonDiv.className='bottomButton';
		var oButton=document.createElement('input');
		oButton.type='image';
		oButton.src='/common/images/btn_return.gif';
		oButton.align='right';
		oButton.id='btnReturnFromList';
		oButton.onclick=this.returnFunction;
		this.returnButtonDiv.appendChild(oButton);
	}
};

/**
 * TODO:订单类Order
 * 目标--方便生成订单信息，减少订单格式错误
 * 参数：1.key；2.value；3.template
 */
oRoot.Order=function(){
	this.itemArray=[];
	this.addItem=function(){
		
	};
	this.toString=function(){
		
	};
};
var Order=oRoot.Order;
